#pragma once
#include <iostream>
#include <functional>
#include "InetAddr.hpp"
using func_t = std::function<void()>;
class Connection;
using connection_t = std::shared_ptr<Connection>;
class Connection
{
public:
    Connection(int sockfd):_sockfd(sockfd)
    {

    }

    ~Connection()
    {

    }
    void InsertMethod(const func_t& recver,const func_t& sender,const func_t& excepter)
    {
        if(recver!=nullptr)
        {
            _recver = recver;
        }   
        if(sender!=nullptr)
            _sender = sender;
        if(excepter!=nullptr)
            _excepter = excepter;
    }
    void SetPeerAddrInfo(InetAddr& peer)
    {
        _peer = peer;
    }
    void Send()
    {
        if(_sender!=nullptr)
            _sender();
    }
    void Recv()
    {
        if(_recver!=nullptr)
            _recver();
    }    
    void Except()
    {
        if(_excepter!=nullptr)
            _excepter();
    }
    int Sockfd()
    {
        return _sockfd;
    }
private:
    int _sockfd;
    InetAddr _peer;

    //
    //回调方法
    func_t _sender;//写
    func_t _recver;//读
    func_t _excepter;//处理异常

};